<template>
  <div>
    <div  style="padding:0 0px 10px 0px; border-bottom:1px solid #f7f7f7;">
        <el-button type="info" @click="$router.go(-1)" icon="el-icon-arrow-left" size="mini">返回</el-button>
    </div>
    <el-row>
      <el-col :span="24">
        <el-form :model="Edit" ref="Edit" :rules="rulesinfo" label-width="100px" label-position="top" :inline="true" size="small" >
          <el-form-item label="类型" prop="StatusID">
            <el-select v-model="Edit.StatusID" style="width:100%">
              <el-option v-for="(item,index) in TypeList.Type" :key="index.pk_TypeID" :value="item.ID" :label="item.TypeName_CHS"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="状态" prop="TypeID">
            <el-select v-model="Edit.TypeID" style="width:100%">
              <el-option v-for="(item,index) in TypeList.Status" :key="index.StatusID" :value="item.ID" :label="item.StatusName_CHS"></el-option>
            </el-select>
          </el-form-item>
          
          <el-form-item label="开始时间" prop="StartDate">
              <el-date-picker v-model="Edit.StartDate"
                type="datetime"
                placeholder="选择日期时间"
                 style="width:100%"
              ></el-date-picker>
          </el-form-item>
          <el-form-item label="结束时间" prop="EndDate">
            <el-date-picker
              v-model="Edit.EndDate"
              type="datetime"
              placeholder="选择日期时间"
               style="width:100%"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="标题" prop="Title">
            <el-input placeholder v-model="Edit.Title"></el-input>
          </el-form-item>
          <el-form-item label="描述" prop="Description">
            <el-input type="textarea" :rows="5" v-model="Edit.Description"></el-input>
          </el-form-item>
          <el-form-item label="置顶">
              <el-checkbox v-model="Edit.IsTop" :checked="Edit.IsTop"></el-checkbox>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
    <br />
    <!-- <el-row>
        <el-col span="24">
            <el-upload class="upload-demo" action="https://jsonplaceholder.typicode.com/posts/" :on-change="handleChange" :file-list="fileList">
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">5MB以内</div>
            </el-upload>
        </el-col>
    </el-row>-->
    <div style="border-top:1px solid #f7f7f7;padding-top:10px;">
      <el-button type="primary" size="small" @click="GetNotion('Edit')" icon="el-icon-check">保存</el-button>
      <el-button size="small"  @click="$router.go(-1)" icon="el-icon-close">取消</el-button>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.el-row {
  margin-bottom: 10px;
}
.el-form-item {
  width: 49%;
}
</style>
<script>
export default {
  data() {
    return {
      Edit: {
        StatusID:null,
        TypeID:null,
        StartDate:null,
        EndDate:null,
        Title:null,
        url:null,
        IsTop:false,
        Description:null
      },
      TypeList:[],
      Type:"Add",
      rulesinfo:{
        StatusID:[
          {required:true,message:'请输入内容',trigger:'blur'}
        ],
        TypeID:[
          {required:true,message:"请输入内容",trigger:'blur'}
        ],
        StartDate:[
          {required: true, message: '请选择日期', trigger: 'change'}
        ],
        EndDate:[
          {required: true, message: '请选择日期', trigger: 'change'}
        ],
        Title:[
          {required:true,message:"请输入内容",trigger:'blur'}
        ],
        url:[
          {required:true,message:"请输入内容",trigger:'blur'}
        ],
        Description:[
          {min:1,max:100,message:"长度在1到100之间"}
        ]
      }
    };
  },
  methods: {
    handleChange(file, fileList) {
      this.fileList = fileList.slice(-3);
    },
     GetNotion(Edit){
        this.$refs[Edit].validate((valid) => {
        if (!valid) {
          return false;
        }
        //console.log(this.Edit)
        //执行请求
        this.$axios({
          url: "/HrApi/NoticeList/UpdateNotion",
          method: "POST",
          data: this.$Qs.stringify({
            Edit: JSON.stringify(this.Edit),
            Type: this.Type,
            pk_User:this.$store.state.UserInfo.pk_User
          }),
        }).then((res) => {
          if (!res.data.code) {
            if(this.Type==="Add"){
              //添加成功，重置表单
            this.$refs[Edit].resetFields();
            }
            this.$message.success(res.data.msg);
          } else {
            this.$message.error(res.data.msg);
          }
        })
      })
      }
  },
  mounted(){
    if(Object.keys(this.$route.query).length){
        this.Type = "Edit";
        this.$axios({
        url: "/HrApi/NoticeList/GetNoticeName",
        method: "GET",
        params:{
          NameID: this.$route.query["pk_Name"],
          pk_user:this.$store.state.UserInfo.pk_User
        },
        }).then((res) => {
        if (!res.data.code) {
          this.Edit = res.data.data;
        } else {
          this.$message.error(res.data.msg);
        }
      })
      };
      //获取类型
      this.$axios({
      url: '/HrApi/NoticeList/GetTypeList',
      method: 'GET'
    }).then(res => {
      this.TypeList = res.data.data
    })
  }
}
</script>
